package cn.edu.scau.cmi.chenbingquan.client;

import cn.edu.scau.cmi.chenbingquan.interProgramming.GraduateStudent;
import cn.edu.scau.cmi.chenbingquan.interProgramming.UndergraduateStudent;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

// 接口编程用户类
public class InterProgrammingClient extends Application {
	private Pane root = new Pane();
	private ComboBox<String> comboBox;
	private Button build;
	
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage stage) {
		root.setStyle("-fx-background-color: linear-gradient(to bottom right, ANTIQUEWHITE, CORNFLOWERBLUE)");
		root.setPrefSize(400, 300);
		
		comboBox = new ComboBox<>();
		comboBox.getItems().addAll("大学生", "研究生");
		comboBox.setPromptText("请选择要创建的学生");
		comboBox.setPrefSize(180, 40);
		comboBox.setLayoutX(60);
		comboBox.setLayoutY(50);
		
		build = new Button("创建");
		build.setPrefSize(60, 40);
		build.setLayoutX(260);
		build.setLayoutY(50);
		root.getChildren().addAll(comboBox, build);
		
		Scene scene = new Scene(root);
		stage.setScene(scene);
		stage.getIcons().add(new Image("cn/edu/scau/cmi/chenbingquan/image/窗口左上角图标.png"));
		stage.setTitle("接口编程");
		stage.setResizable(false);
		stage.show();
		
		addEvents();
	}
	
	// 添加事件
	private void addEvents() {
		// 创建按钮点击事件
		build.setOnMouseClicked(e -> {
			if(comboBox.getValue() == null) {
				showMessageStage("请先选择要创建的学生!!");
			} else if(comboBox.getValue().equals("大学生")) {
				showMessageStage(new GraduateStudent().learning());
			} else if(comboBox.getValue().equals("研究生")) {
				showMessageStage(new UndergraduateStudent().learning());
			}
		});
	}
	
	// 显示信息窗口
	private void showMessageStage(String message) {
		
		VBox vBox = new VBox(60);
		vBox.setAlignment(Pos.CENTER);
		vBox.setStyle("-fx-background-color: ANTIQUEWHITE");
		vBox.setPrefSize(300, 250);
				
		Text text = new Text(message);
		text.setStyle("-fx-font-size: 25; -fx-fill: orange"); 
				
		Button button = new Button("确定");
		button.setPrefSize(60, 30);
		vBox.getChildren().addAll(text, button);
				
		Stage stage = new Stage();
		Scene scene = new Scene(vBox);
		stage.setScene(scene);
		stage.setTitle("学习方式");
		stage.show();
				
		// 事件
		button.setOnMouseClicked(e -> stage.close() ); 		// 关闭窗口
	}
}
